#ifndef CRAYTRACER_H
#define CRAYTRACER_H

class CPhotonMapping;

#include "ccamera.h"
#include "cpoint3f.h"
#include "cvecteur3f.h"
#include "craytracable.h"
#include "cphotonmapping.h"
#include "clight.h"
#include <QImage>

class CRaytracer : public QThread
{
public:
	CRaytracer();
	~CRaytracer();

        bool draw(QImage * output, int nb_reflects, int yLine, int montecarlo, bool usePM);
	bool drawPhoton(QImage * output, int nb_reflects);
	void traceRec (CRay Ray, float coef, unsigned nb_reflects, float& r, float& g, float& b);
	void traceChannelRec (CRay Ray, float coef, unsigned nb_reflects, float& c, int channel);
	void traceRecPhoton (CRay Ray, float coef, unsigned nb_reflects, float& r, float& g, float& b);
	void traceChannelRecPhoton (CRay Ray, float coef, unsigned nb_reflects, float& c, int channel);
	bool verif_init();

	void set_height(int h);
	void set_width(int w);
	void set_EnvironmentMaterial(CMaterial);

	void add_objects(CRayTracable * obj);
	void remove_objects(CRayTracable * obj);
	void remove_objects(int i);
	void add_ligth(CLight * l);
	void remove_light(CLight * l);
	void remove_light(int i);

	int scene_width;
	int scene_height;
	CCamera * Camera;
	QVector<CLight *> lights;
	QVector<CRayTracable *> objects;
	CMaterial EnvironmentMaterial;

	CPhotonMapping * photonMapping;

	int progressPercent;

        QMutex * mutex;
        QMutex * mutex2;

        QImage * output;
        int nb_reflects;
        int y;
        int nb_montecarlo;

        void run();

        bool usePhotonMapping;
};

#endif // CRAYTRACER_H
